package cs4280.ass2.util;

import org.apache.commons.lang.StringUtils;

import cs4280.ass2.entity.ScheduleSeatDetail;
import cs4280.ass2.exception.ValidateException;

public class ScheduleSeatDetailUtils {
	
	public static void validate(ScheduleSeatDetail scheduleSeatDetail) throws ValidateException {
		if (scheduleSeatDetail.getId() < 0L) {
			throw new ValidateException("message.error.validate.scheduleSeatDetail.id.negativeValue");
		}
		if (scheduleSeatDetail.getScheduleId()< 0L) {
			throw new ValidateException("message.error.validate.scheduleSeatDetail.scheduleId.negativeValue");
		}
		if (!isValidScheduleSeatDetailStatus(scheduleSeatDetail)) {
			throw new ValidateException("message.error.validate.scheduleSeatDetail.seatStatus.invalid");
		}
		if (StringUtils.isBlank(scheduleSeatDetail.getRow())) {
			throw new ValidateException("message.error.validate.scheduleSeatDetail.seatLocation.empty");
		}
	}
	
	public static boolean isValidScheduleSeatDetailStatus(ScheduleSeatDetail scheduleSeatDetail) {
		return (scheduleSeatDetail.getSeatStatus().equals(ScheduleSeatDetail.SEAT_STATUS_AVAILABLE) ||
		        scheduleSeatDetail.getSeatStatus().equals(ScheduleSeatDetail.SEAT_STATUS_PROCESSING)||
		        scheduleSeatDetail.getSeatStatus().equals(ScheduleSeatDetail.SEAT_STATUS_RESERVED) ||
		        scheduleSeatDetail.getSeatStatus().equals(ScheduleSeatDetail.SEAT_STATUS_SOLD));
	}
}
